﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Servicecomb.Saga.Omega.AspNetCore.Extensions;

namespace Ebusiness_Framework.DistributedTransaction
{
    /// <summary>
    /// 分布式事务扩展方法
    /// </summary>
    public static class DistributedTransactionServiceCollectionExtentions
    {
        public static IServiceCollection UseDistributedTransaction(this IServiceCollection services, IConfiguration configuration)
        {
            DistributedTransactionOptions options = configuration.GetSection("DistributedTransaction").Get<DistributedTransactionOptions>();
            // 3、配置Servceicomb-pack
            services.AddOmegaCore(option =>
            {
                option.GrpcServerAddress = options.GrpcServerAddress; // 1、协调中心地址
                option.InstanceId = options.InstanceId;// 2、服务实例Id
                option.ServiceName = options.ServiceName;// 3、服务名称
            });
            return services;
        }
    }
}
